package test2;

import java.util.ArrayList;
import java.util.Scanner;

/*
* 学生管理系统，循环操作相关功能，直至退出
* 功能1：展示低于输入成绩的学生信息
* 功能2：根据学号展示信息并且修改成绩
* 功能3：退出
* */
public class Demo {

    public static void main(String[] args) {
        //集合，保存学生信息
        ArrayList<Student> list = new ArrayList<>();

        Student student = new Student();

        student.setName("德华");
        student.setScore(100);
        student.setIdNumber(1001);

        list.add(student);

        Student student1 = new Student();
        student1.setName("于晏");
        student1.setScore(80);
        student1.setIdNumber(1002);

        list.add(student1);

        Scanner sc = new Scanner(System.in);

       while(true){
           System.out.println("输入指令 功能1:1,功能2:2,退出:3");

           int order = sc.nextInt();

           switch (order){
               case 1:
                   showStudentInfo(list);
                   break;
               case 2:
                   updateStudentScore(list);
                   break;
               case 3:
                   System.out.println("您已退出系统");
                   return;
           }
       }



    }

    //功能1
    public static void showStudentInfo(ArrayList<Student> list){
        //创建Scanner对象
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入一个成绩");
        //接收输入成绩
        int score = sc.nextInt();


        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getScore()<score){
                System.out.println(list.get(i));
            }
        }

    }

    //功能2
    public static void updateStudentScore(ArrayList<Student> list){
        //创建Scanner对象
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入一个学号");
        //接收输入学号
        int idNumber = sc.nextInt();

        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getIdNumber()==idNumber){
                //修改学生成绩
                System.out.println("请输入一个新成绩");
                int score = sc.nextInt();

                list.get(i).setScore(score);

                System.out.println("修改后的学生信息:"+list.get(i));

                break;
            }
            if(i==list.size()-1){
                System.out.println("当前学号未匹配的任何人的信息");
            }
        }

    }
}
